package com.ctshk.app.order.bus.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.order.bus.req.BusOrderCreateB2CReq;
import com.ctshk.rpc.order.bus.req.BusOrderPayReq;
import com.ctshk.rpc.order.bus.service.IBusOrderAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

@Api(tags = "巴士服务—APP")
@RestController
@RequestMapping("/bus/order")
public class BusOrderController extends BaseController {

	@DubboReference
	IBusOrderAppService busOrderAppServiceImpl;

	@ApiOperation(value="巴士订单-填写订单信息", notes="巴士订单-填写订单信息")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "填写订单信息", operDesc = "填写订单信息")
	@PostMapping("/write")
	public Result busOrderWrite(@RequestBody @Valid BusOrderCreateB2CReq busOrderWriteReq) {
		TokenUser user = getCurrentUser(getRequest());
		return busOrderAppServiceImpl.writeBusOrder(busOrderWriteReq,user);
	}

	@ApiOperation(value="巴士订单-支付订单", notes="巴士订单-支付订单")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "巴士订单-支付订单", operDesc = "巴士订单-支付订单")
	@PostMapping("/pay")
	public Result busOrderPay(@RequestBody @Valid BusOrderPayReq busOrderPayReq) {
		return busOrderAppServiceImpl.busOrderPay(busOrderPayReq);
	}

	@ApiOperation(value="巴士订单-取消订单", notes="巴士订单-取消订单")
	@OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "巴士订单-取消订单", operDesc = "巴士订单-取消订单")
	@PostMapping("/pay/cancel/{id}")
	public Result busOrderCancel(@PathVariable("id") Long id) {
		TokenUser user = getCurrentUser(getRequest());
		return busOrderAppServiceImpl.busOrderCancel(id,user);
	}

}
